home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / me_cd22.zip / DOC.ZIP / OBJECT.DOC < prev    next >
Text File  |  1992-04-27  |  8KB  |  266 lines

  1. -*-text-*-
  2.  
  3. General decussion of OOP stuff.  Add to insideMutt.
  4.  
  5. Don't do typedefs or structs, go directly to objects.
  6.  
  7.                 LISTS and SETS
  8.                 ----- --- ----
  9.  
  10. Definitions:
  11.   LIST:  an ordered set of heterogeneous objects.
  12.   OSET:  an ordered set of homogeneous objects.
  13.   
  14. Notes:
  15.   A string is an oset.
  16.   I think that an unordered set is easy to fake from an oset.
  17.   Lists and osets expand/contract as needed.
  18.   ???The first element of a list or oset is numbered 1.  This means the
  19.     0-th element is before the first element in a list.  Handy for some
  20.     operations.
  21.   ??? what is the empty set??? []
  22.   Set is a bad name:  how about sequence, chain, list, pool, goo???
  23.     Rejected: vector, collection
  24.  
  25.                  LIST SYNTAX
  26.   Need an empty set: [], at least for notation.
  27.   Nothing special is needed but it might be nice to add some syntactic
  28.     sugar.
  29.   A oset constant:  [1 2 3], the empty set is [].
  30.     Use:  (nth-item ["one" "two" "three"] n) (same as switch)
  31.       (foo ["fee" "fie" "foe" "fum"]) (same as (foo (concat ...))
  32.   From CLisp:  #(item item ...), #() is empty set.  CL book suggests []
  33.     notation is better but users might want to use [] themselves.
  34.  
  35.  
  36.                LIST OPERATIONS
  37. list/oset operations (foo and bar are lists or sets):
  38.   This is array like notation (always uses an index).  Might be pretty
  39.     inefficient/awkward commparded to pointer syntax (ala lisp).
  40.  
  41. (list type list-name):  Create a list.
  42.   All lists are set to the empty list at creation.
  43.   (list string foo):  Create a list of lists.
  44.   (list list string foo):  Create a list of lists containing strings.
  45.     Kinda like a 2d array.
  46.  
  47. #if 0    /* this is array syntax, not list syntax */
  48.   (foo n):  returns the nth element of foo AS AN atom (if possible)
  49.     eg ("abc" 2) => 'b', ([1 2 3] 2) => 2,
  50.     ([[1] [2 2] [3 3 3]] 2) => [2 2].
  51. use (n-items).  Use (cast-to) if need to atomify (atomize?).
  52.   (foo n object):  Replaces the nth element of foo with object.
  53.     eg ("abc" 2 'z') => "azc", ([1 2 3] 2 123) => [1 123 3]
  54.     eg ("abc" 2 "xyz") => ???
  55. use (replace-item)
  56. #endif
  57.  
  58.   (foo) returns the contents of foo.
  59.   (foo object [object ...])
  60.     Clears foo, concatanates all the objects and puts them in foo.
  61.     (foo []) Resets foo, ie foo contains the empty list.
  62.     (foo "testing" " 123") => (foo) == "testing 123".
  63.  
  64.   (length-of foo):  number of objects in foo.
  65.     (length-of []) => 0.
  66.  
  67.   (n-items foo n [z]):
  68.     Trys to return a list of length z made by coping z elements of foo
  69.       starting at (and including) the nth.
  70.     z defaults to 1.
  71.     ???(n-items foo 1) is the first element of foo.
  72.     If (z <= 0) or (n > (length-of foo)) or (foo == []), returns [].
  73.     If ask for more elements than can get, return as much as can.
  74.     (n-items "123" 2) => "2", (n-items "123" 2 2) => "23"
  75.     (n-items [] n z) => []
  76.     ???If need an atom, use (cast-to ...)
  77.   (concat foo bar):  returns a new list.
  78.     (concat [] [])  => []
  79.     (concat foo []) => foo
  80.     (concat [] bar) => bar
  81.  
  82.   (add-to foo n object [object ...]):
  83.     Insert object(s) into foo after the nth element.
  84.     If n >= (length foo), this op would be the same as (foo (concat foo
  85.       bar)) and would save some data copies.  Maybe just use (add-at
  86.       foo (length foo) bar).
  87.     If (n < "first element"), prepend ie same as (foo (concat bar foo))
  88.     (add-to [] n bar)  => ???error, can't save result or just stash in
  89.       RV ie same as (concat [] bar).
  90.     eg (add-to "123" 1 "9") => "1923"
  91.   (remove-items foo n [z]):  Remove z items from foo starting at
  92.       (including) n.  z defaults to 1.  This could be implemented as
  93.       (foo (n-items foo 1 (- n 1)) (n-items foo (+ n 1) (length foo))).
  94.     If (n >= (length foo)) => foo
  95.     If try to remove more elements than in foo, return [].
  96.     If (z <= 0) return foo.
  97.     (remove-items [] n [z]):  [].
  98.   (replace-items foo n z object [object ...])
  99.     Same as (remove-items foo n z)(add-to foo n-1 object [object ...])
  100.  
  101.   Misc:  These could be Mutt routines.
  102.     (is-in foo object [n [m]])   ?? (in-list)
  103.       Returns <something> if object is in list foo.
  104.       Return:  TRUE/FALSE or n/-1
  105.       Start at n, end at m.
  106.       ??? what about arb objects, how compare?
  107.     (apply-to foo Mutt-fcn):  For every item in foo, call Mutt-fcn and
  108.       pass it the nth item of foo.
  109.  
  110. Problems:
  111.   Lists or osets of lists or osets.
  112.   How do I (joe mutt programmer) know what (nth-item foo-list n) is?  Is
  113.     there a (type foo)?  What happens when foo is a user defined object?
  114.     That would mean a central (MM) dictionary of tuples:  (object type
  115.     #, object description).  Many disjoint programs might share objects
  116.     so the compiler would have to generate code that registered an
  117.     object and stashed the type so it could be used for type checking,
  118.     etc.  1 byte is probably not enough for all the possible types.
  119.     This would be a pretty cool concept - ME could generate types for
  120.     buffer/bag/region stats, etc so I could do better type checking.
  121.     (msg) would work automagically with objects.  On the other hand it
  122.     might a be a real drag to implement, slow things down and use up
  123.     lots more space.  If I don't implement this, JP would have to know
  124.     (by putting a type field in the object) how to figure out the object
  125.     type.  Maybe the best idea is just punt lists and stick with osets.
  126.  
  127.  
  128.  
  129.                    OBJECTS
  130.                    -------
  131.  
  132. (object
  133.   DATA
  134.   {
  135.   }
  136.   CREATE    ;; constructer
  137.   {
  138.   }
  139.   FREE        ;; destructer
  140.   {
  141.   }
  142.   methods
  143.   overloading
  144.   ...
  145. }
  146.  
  147. A struct is just the data subset of this.
  148.  
  149. Object data is built on top of basic/atomic Mutt types:  NUMBER (byte,
  150. int, INT), STRING, ?VOID, REAL, BOOLEAN, BLOB, FCNPTR, LIST, array.
  151.  
  152.                   PROBLEMS
  153.                   --------
  154. How manage types that are:
  155.   - fixed length,    fixed object size     (NUMBER, REAL, BOOLEAN)
  156.   - fixed length,    unknown object size (FCNPTR)
  157.   - unknown length,  fixed object size     (STRING)
  158.   - unknown length,  unknown object size (LIST)
  159.   - objects that are built from the above types
  160.     How store, get and set.
  161.   
  162. What about:
  163.   - (loc object):  How do I type check?
  164.   - How do I type check objects?  do I need to?
  165.  
  166.  
  167.                    EXAMPLES
  168.                    --------
  169.  
  170. (object Buffer
  171.   DATA
  172.   {
  173.     (int buffer-id)
  174.   }
  175.   CREATE    ;; constructer
  176.   {
  177.     (buffer-id (create-buffer))
  178.   }
  179.   FREE        ;; destructer
  180.   {
  181.     (free-buffer buffer-id)
  182.   }
  183.   info
  184.   {
  185.   }
  186.   methods
  187.   overloading
  188.   ...
  189. }
  190.   
  191. (object Mark
  192.   DATA
  193.   {
  194.     (int mark-id)
  195.   }
  196.   CREATE    ;; constructer
  197.   {
  198.     (mark-id (create-mark))
  199.   }
  200.   FREE        ;; destructer
  201.   {
  202.     (free-mark mark-id)
  203.   }
  204.   methods
  205.   overloading
  206.   ...
  207. }
  208.  
  209. mark-rings
  210.  
  211.  
  212.                IMPLEMENTATIONS
  213.                ---------------
  214.  
  215. Smalltalk Model
  216.  
  217. code varables        object table        objects
  218. Var : contents        index : pointer        address : contents
  219.   list a : 3            1 : aaa
  220.   string b : 1            2 : xxx
  221.                 3 : bbb
  222.  
  223.  
  224. Each object varible in the code contains a 2 byte object number that is
  225. an index into the object table.  The object table contains pointers to
  226. the actual objects.
  227.  
  228. Get:  The address of object n is:  object-table[n]
  229. Set:
  230. Allocate:
  231.   Look though object table until find an index that is unused.
  232.     If none:  GC.
  233.     Repeat lookup.
  234.     If object table full (GC didn't free anything):
  235.       Expand object table.
  236.       If can't:  fail.
  237.   Return index.
  238. GC:
  239.   (1) Mark all entries in the object table as dead.
  240.   (2) For all live code object variables, mark object-table[var-index]
  241.     as live.
  242.   (3) Free all objects marked as dead in the object table.
  243.  
  244. Variation 1 on the Smalltalk model:
  245.   Move object table into the objects.
  246.     - Don't use a object table.
  247.     - Each object is linked to the next object.
  248.     - Vars contain pointers to the actual objects.
  249.     Pros:
  250.       - Less to think about and manage.
  251.       - Object look up is faster.
  252.     Cons:
  253.       - Probably uses more space.
  254.  
  255. Variation 2:
  256.   Copy objects instead of mark/sweep:
  257.     Look though object table
  258.       If object in use, copy it to a new list
  259.     Free all objects in the orginal list.
  260.  
  261.  
  262. When garbage collect:
  263.   - When malloc fails
  264.   - When a program is done running
  265.   - When a block is freed
  266.